package cn.ly.net.pic;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;


public class UploadServer {
	public static void main(String[] args) throws IOException {
		ServerSocket ss = new ServerSocket(19199);
		
		Socket s = ss.accept();
		
		BufferedInputStream bis = new BufferedInputStream(s.getInputStream());
		
		//封装成图片
		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("mm.jpg"));
		
		byte[] bys = new byte[1024];
		int len = -1;
		while( (len = bis.read(bys)) != -1){
			bos.write(bys,0,len);//用0，len，len为有效长度，这样能避免写入数组中空的数据。
		}
		
		OutputStream os = s.getOutputStream();
		os.write("图片上传成功".getBytes());
		
		
		bos.close();
		s.close();
	
	}
}
